const mongo = require('mongoose')
const { url } = require('./config/database')
mongo.connect(url)
const db = mongo.connection
db.on('open', () => {
  console.log('ok')
})
const user = new mongo.Schema({
  username: {
    type: String,
    required: true,
    trim: true,
    minLength: 1,
    index: true,
    unique: true
  },
  password: {
    type: String,
    required: true,
    trim: true,
    minLength: 1
  },
  role: {
    type: String,
    required: true,
    default: 'user',
    enum: ['user', 'admin']
  },
  initialLevel: {
    type: Number,
    required: true,
    enum: [0, 1, 2, 3],
    default: 0
  },
  learnPurpose: {
    type: Number,
    required: true,
    enum: [0, 1, 2, 3, 4, 5],
    default: 0
  },
  planning: {
    type: Number,
    required: true,
    enum: [0, 1, 2, 3, 4],
    default: 0
  },
  learnStyle: {
    type: Number,
    required: true,
    default: 0
  }
})
const User = mongo.model('user', user)
const ha = new User({ username: 'root', password: '$2a$10$am.Z2/7L0RXH1TCswN8/X.3VBFGCFZDoJPL0d3Odh/mV8zOetpiQq', role: 'admin' })
ha.save((err) => {
  if (err) {
    console.log('滚')
    return
  }
  console.log('fuckyou')
})
